package com.yangming.springboot.config;

import com.yangming.springboot.interceptors.NoLoginInterCeptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @创建人 ym
 * @创建时间 2021/3/15 0015
 * @描述配置类，配置拦截器，让拦截器生效
 **/

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {


    //把我们写的拦截器交给spring IOC
    @Bean
    public NoLoginInterCeptor noLoginInterCeptor(){
        return new NoLoginInterCeptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        /*
        * 配置拦截器内容，一个是传入拦截器方法，自定义拦截器方法是继承HandlerInterceptorAdapter基类的拓展类，add添加拦截路径名，exclude添加不做拦截的内容为何
        * */
        registry.addInterceptor(noLoginInterCeptor()).addPathPatterns("/**").excludePathPatterns("/index", "/user/login", "/css/**", "/images/**", "/js/**", "/lib/**");
    }

}
